package com.yanggu.scala.chapater12.caseclass

import CaseClassDemo01.{Currency, Dollar, NoAmount}

object CaseClassDemo02 {

  def main(args: Array[String]): Unit = {
    //通过模式匹配将样例类对象中的字段提取出来, 以供后面的程序使用
    for (amt <- Array(Dollar(1000.0), Currency(1000.0, "RMB"), NoAmount)) {
      val result = amt match {
        case Dollar(value) => value
        case Currency(value, unit) => value + "\t" + unit
        case NoAmount => "Nothing"
      }
      println(result)
    }
  }

}
